import request from './request'

export class ApiService {
    constructor(url) {
        this.baseUrl = url;
    }

    //获取列表数据
    // eslint-disable-next-line no-unused-vars
    list(id) {
        return request({
            url: this.baseUrl + '/' + id,
            method: 'get',
        })
    }

    post(data){
        return request({
            url: this.baseUrl,
            method: 'post',
            data: data
        })
    }
    //新增数据
    create(data) {
        return request({
            url: this.baseUrl,
            method: 'post',
            data: data
        })
    }

    //查询数据
    search(data) {
        return request({
            url: this.baseUrl,
            method: 'post',
            data: data
        })
    }

    //修改数据
    update(data) {
        return request({
            url: this.baseUrl,
            method: 'put',
            data: data
        })
    }

    //删除数据
    delete(id) {
        return request({
            url: this.baseUrl + '/' + id,
            method: 'delete'
        })
    }

    //获取数据详情
    getViewById(id) {
        return request({
            url: this.baseUrl + '/' + id,
            method: 'get'
        })
    }

    //获取数据
    getViewList() {
        return request({
            url: this.baseUrl,
            method: 'get'
        })
    }

    getParams(params) {
        return request({
            url: this.baseUrl,
            method: "get",
            params: params,
        })
    }

    getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
        }
        return "";
    }
}
